#encoding: utf-8
require 'date'
require 'time'

#This array should be maintenanced manually with aids from gen_holiday()
def is_holiday the_day #using Date type
  [
    '2022-01-01','2022-01-02','2022-01-08','2022-01-09','2022-01-15','2022-01-16','2022-01-22','2022-01-23',#'2022-01-29','2022-01-30',
    '2022-01-31','2022-02-01','2022-02-02','2022-02-03','2022-02-04','2022-02-05','2022-02-06',#春节
    '2022-02-12','2022-02-13','2022-02-19','2022-02-20','2022-02-26','2022-02-27','2022-03-05','2022-03-06','2022-03-12','2022-03-13','2022-03-19','2022-03-20','2022-03-26','2022-03-27',#'2022-04-02',
    '2022-04-03','2022-04-04','2022-04-05',#清明
    '2022-04-09','2022-04-10','2022-04-16','2022-04-17','2022-04-23','2022-04-24',#'2022-04-30',
    '2022-05-01','2022-05-02','2022-05-03','2022-05-04','2022-05-05','2022-05-06','2022-05-07', #五一
    '2022-05-08','2022-05-14','2022-05-15','2022-05-21','2022-05-22','2022-05-28','2022-05-29',
    '2022-06-03','2022-06-04','2022-06-05',#端午
    '2022-06-11','2022-06-12','2022-06-18','2022-06-19','2022-06-25','2022-06-26','2022-07-02','2022-07-03','2022-07-09','2022-07-10','2022-07-16','2022-07-17','2022-07-23','2022-07-24','2022-07-30','2022-07-31','2022-08-06','2022-08-07','2022-08-13','2022-08-14','2022-08-20','2022-08-21','2022-08-27','2022-08-28','2022-09-03','2022-09-04',
    '2022-09-10','2022-09-11','2022-09-12',#中秋
    '2022-09-17','2022-09-18','2022-09-24','2022-09-25',
    '2022-10-01','2022-10-02','2022-10-03','2022-10-04','2022-10-05','2022-10-06','2022-10-07',#国庆
    #'2022-10-08','2022-10-09',
    '2022-10-15','2022-10-16','2022-10-22','2022-10-23','2022-10-29','2022-10-30','2022-11-05','2022-11-06','2022-11-12','2022-11-13','2022-11-19','2022-11-20','2022-11-26','2022-11-27','2022-12-03','2022-12-04','2022-12-10','2022-12-11','2022-12-17','2022-12-18','2022-12-24','2022-12-25','2022-12-31'
  ].each { |d|
        return true if the_day == Date.parse(d) }
    return false
end

#order_time = Time.new
#time_1 = Time.parse(order_time.strftime('%Y-%m-%d 09:00:00'))
#time_2 = Time.parse(order_time.strftime('%Y-%m-%d 14:00:00'))
#puts time_1
#puts time_2
#puts order_time > time_1 && order_time < time_2

def gen_holidays
    the_day = Date.parse('2022-01-01')
    text =  "["
    365.times do
      if the_day.wday == 6 || the_day.wday == 7
        if the_day.wday == 6
          text += "\n'#{the_day}','#{the_day.next_day}',"  
          the_day = the_day.next_day.next_day
        else
          text += "\n'#{the_day}',"  if the_day.wday == 7
          the_day = the_day.next_day
        end
      else
        the_day = the_day.next_day
      end
    end
    text += "\n]"
end
#use to generate holiday data draft
